package archimede;

import java.awt.Graphics;
import java.util.Properties;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

public class PannelloPiantina extends JPanel {

	private int tab;
	private Piantina tabbed;
	private StartingWindow st;
	private BarraPulsanti barra;

	protected void paintComponent(Graphics g) {
		setOpaque(false);
		g.drawImage((new ImageIcon(ClassLoader.getSystemResource("sfondo.jpg"))).getImage(), 0, 0, null);
		super.paintComponent(g);
	}

	public PannelloPiantina(Piantina tabbed, int count, StartingWindow st) {
		super();
		this.st = st;
		this.tabbed = tabbed;
		tab = count;
		setLayout(new MigLayout());
		barra = new BarraPulsanti(this, st);
		add(barra, "dock north");
	}

	public void refresh() {
		paintAll(getGraphics());
	}

	public void setTitle(String title) {
		tabbed.setTitleAt(tab, title);
	}

	public void salva() {
		// System.out.println("tab "+tab);
		Salva s = new Salva(barra.getpanel(), st.getProject());
		// System.out.println("dir "+st.getCount());
		s.salvaImmaginePNG("piantina" + tab + ".png");
	}

	public String getTitle() {
		return tabbed.getTitleAt(tab);
	}

	public void setPiantina(String path) {
		Properties pc = System.getProperties();
		String homePath = pc.getProperty("user.home");
		String directoryProject = homePath + pc.getProperty("file.separator") + "ArchimedeSuper" + pc.getProperty("file.separator") + st.getProject()
				+ pc.getProperty("file.separator");

		barra.setElement(directoryProject + "piantina" + tab + ".png");
	}

	

	public String print() {
		return tabbed.getTitleAt(tab);
	}

	public int getTab() {
		return tab;
	}

}
